package com.ehotting.edsta.mqbd.testability.http.caller;

import com.alibaba.fastjson.JSON;
import com.ehotting.eaf.netty.loggers.NettyMsgReceiveLogger;
import com.ehotting.edsta.mqbd.api.enums.SysModuleEnum;
import com.ehotting.edsta.mqbd.testability.service.ITestabilityService;
import com.ehotting.mqbd.api.MqActionConstants;
import com.ehotting.mqbd.api.bean.CommonResponse;
import com.ehotting.mqbd.api.bean.MQDataAble;
import com.ehotting.mqbd.api.bean.MQHttpData;
import com.ehotting.mqbd.api.bean.solver.SolverStateBean;
import com.ehotting.mqbd.core.call.CallerAbstract;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;


@Slf4j
public class TestabilityCaller extends CallerAbstract {

    @Autowired
    private NettyMsgReceiveLogger nettyMsgReceiveLogger;
    @Autowired
    private ITestabilityService testabilityService;

    @Override
    public void doAction(SolverStateBean serverState, MQDataAble mqData)  {

        MQHttpData data  = (MQHttpData) mqData;
        CommonResponse commonResponse = null;
        if(MqActionConstants.RE_POST.equals(data.getAction())){
             commonResponse = testabilityService.rePostService(
                     data.getRequest(),
                     serverState.getSolverInfo(),
                     mqData.getAuthorization());
        }else if(MqActionConstants.RE_UPLOAD.equals(data.getAction())){
             commonResponse = testabilityService.rePostUploadService(
                     data.getRequest(),
                     serverState.getSolverInfo(),
                     mqData.getAuthorization());
        }
        nettyMsgReceiveLogger.info(JSON.toJSONString(commonResponse));
        data.setResponse(commonResponse);
    }

    @Override
    public void validData(MQDataAble mqDataAble) {

    }

    @Override
    public String getModuleName() {
        return SysModuleEnum.TESTABILITY.getName();
    }
}
